﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace Futaba.SBus
{
	/// <summary>
	/// A base class which implemented the <see cref="INotifyPropertyChanged"/>
	/// </summary>
	public abstract class NotifyPropertyChangedBase : INotifyPropertyChanged
	{

		/// <summary>
		/// Raised when a properties value of this instance changes
		/// </summary>
		public event PropertyChangedEventHandler PropertyChanged;

		/// <summary>
		/// Raise the <see cref="PropertyChanged"/> for the provided property
		/// </summary>
		/// <param name="propName">the name of the property which's value changed. may be left empty, 
		/// if called from within the properties setter, as the <see cref="CallerMemberNameAttribute"/> is used</param>
		protected virtual internal void RaisePropertyChanged([CallerMemberName] string propName = null)
		{
			if (PropertyChanged == null || string.IsNullOrEmpty(propName))
				return;

			var args = new PropertyChangedEventArgs(propName);
			PropertyChanged(this, args);
		}

	}
}
